package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

//使用预编译sql 完成update
public class JDBCDemo08 {
    public static void main(String[] args) {
        //需求：根据ID修改用户的信息
        try (Connection connection = DBUtil.getConnection()){
            String sql = "UPDATE userinfo " +
                         "SET username=?, password=?, nickname=?, age=? " +
                         "WHERE id=?";
            PreparedStatement ps = connection.prepareStatement(sql);
            ps.setString(1,"韩梅");
            ps.setString(2,"777");
            ps.setString(3,"小梅");
            ps.setInt(4,22);
            ps.setInt(5,3);
            int i = ps.executeUpdate();
            if (i>0){
                System.out.println("修改成功");
            }else {
                System.out.println("修改失败");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
